package com.example.logic.user.impl;

import java.util.List;
import com.example.dao.user.IUserDao;
import com.example.logic.user.IUserLogic;
import com.example.model.Example;

public class UserLogicImpl implements IUserLogic {
	
	private IUserDao userDao;

	public IUserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}
	
	public Example addUser(String username, String password, String email) {
		Example u=new Example();
		u.setName(username);
		u.setPassword(password);
		u.setEmail(email);
		userDao.save(u);
		return u;
	}

	public Example loginValid(String username, String password) {
		return userDao.findUserByNameAndPass(username, password);
	}

	public boolean validateName(String username) {
		Example u = userDao.getUserByName(username);
		if(u!=null){
			return true;
		}
		return false;
	}

	public void delete(String id) {
		userDao.delete(new Long(id));
	}

	public List<Example> getUsers() {
		return userDao.getUsers();
	}

	public void save(Example e) {
		userDao.save(e);
	}

	public Example getUserById(String id) {
		return userDao.getUserById(new Long(id));
	}

}
